package main

import (
	"class_bff/class"
	"class_bff/global"
	"class_bff/pkg"
	"context"
	"fmt"
	"github.com/Baidu-AIP/golang-sdk/aip/censor"
	"github.com/goccy/go-json"
)

func main() {
	pkg.InitRabbitMq()
	pkg.SimpleConsumer("class_comment", callBulk)
}

func callBulk(str string) {
	var data = global.Comments{}
	json.Unmarshal([]byte(str), &data)
	//内容审核
	client := censor.NewClient("1JBYg2UgadUE8LQK8vjvmXcd", "b91gdbkOuC35vXcvgH0ejhC0JkryAzHE")
	res := client.TextCensor("审核文字")
	var resp global.T
	json.Unmarshal([]byte(res), &resp)
	if resp.Conclusion != "合规" {
		fmt.Println("内容不合规")
		return
	}
	a := pkg.Comment()
	_, err := a.CreateComment(context.Background(), &class.CreateCommentRequest{
		UserId:  int64(data.UserId),
		ClassId: int64(data.ClassId),
		Comment: data.Comment,
	})
	if err != nil {
		fmt.Println("添加评论失败")
		return
	}
	fmt.Println("添加评论成功")
}
